<template>
  <div class="search-container">
    <div class="header-container">
      <a-page-header
        style="
          border: 1px solid #eaeaea;
          border-radius: 8px;
          box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
        "
        title="搜索结果"
        sub-title="找到与您搜索相关的内容"
        @back="() => $router.go(-1)"
      />
    </div>

    <div class="search-keyword-box">
      <div class="keyword-tag">
        <span class="keyword-icon">🔍</span>
        <span class="keyword-text">搜索关键词: "{{ keyword }}"</span>
      </div>
    </div>

    <div v-if="searchStore.searchdemo.length > 0" class="search-results">
      <div
        class="search-item"
        v-for="(item, index) in searchStore.searchdemo"
        :key="index"
        @click="handlebounceTodetail(item.iid)"
      >
        <div class="item-img">
          <img :src="item.image" alt="内容图片" />
        </div>
        <div class="item-content">
          <h2 class="item-title">{{ item.title }}</h2>
          <p class="item-desc">{{ item.paper }}</p>
        </div>
      </div>
    </div>

    <div v-else class="empty-result">
      <div class="empty-icon">🔍</div>
      <div class="empty-text">未找到相关搜索结果</div>
      <div class="empty-tip">请尝试使用其他关键词进行搜索</div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, reactive } from 'vue'
import { useSearchStore } from '@/stores/search/search'
import { useRoute, useRouter } from 'vue-router'
const route = useRoute()
const router = useRouter()
const searchStore = useSearchStore()
const loading = ref(false)

const keyword = route.query.keyword as string
console.log(keyword, '键盘搜索关键词')

searchStore.searchResultAction(keyword)

function handlebounceTodetail(iid: number) {
  router.push({
    path: `/adminskilldetail/${iid}`,
  })
}
</script>

<style lang="less" scoped>
.search-container {
  max-width: 800px;
  margin: 0 auto;
  padding: 20px;
}

.header-container {
  margin-bottom: 20px;
  border-radius: 8px;
  overflow: hidden;
}

.search-keyword-box {
  margin-bottom: 20px;
  padding: 0 10px;

  .keyword-tag {
    display: inline-flex;
    align-items: center;
    padding: 8px 16px;
    background-color: #e6f7ff;
    border: 1px solid #91d5ff;
    border-radius: 20px;
    font-size: 14px;

    .keyword-icon {
      margin-right: 8px;
      font-size: 16px;
    }

    .keyword-text {
      font-weight: 500;
      color: #1890ff;
    }
  }
}

.search-results {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.search-item {
  display: flex;
  background-color: #fff;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  transition: all 0.3s ease;
  cursor: pointer;
  border: 1px solid #f0f0f0;

  &:hover {
    transform: translateY(-3px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
    border-color: #1890ff;

    .item-title {
      color: #1890ff;
    }
  }

  .item-img {
    width: 120px;
    min-width: 120px;
    height: 120px;
    overflow: hidden;

    img {
      width: 100%;
      height: 100%;
      object-fit: cover;
      transition: transform 0.3s ease;
    }

    &:hover img {
      transform: scale(1.05);
    }
  }

  .item-content {
    flex: 1;
    padding: 26px;
    display: flex;
    flex-direction: column;
    justify-content: center;

    .item-title {
      font-size: 26px;
      font-weight: 600;
      color: #333;
      margin-bottom: 8px;
      transition: color 0.3s ease;
      display: -webkit-box;
      line-clamp: 1;
      -webkit-box-orient: vertical;
      overflow: hidden;
    }

    .item-desc {
      font-size: 24px;
      color: #666;
      line-height: 1.5;
      display: -webkit-box;
      line-clamp: 2;
      -webkit-box-orient: vertical;
      overflow: hidden;
    }
  }
}

.empty-result {
  text-align: center;
  padding: 40px 20px;
  background-color: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);

  .empty-icon {
    font-size: 48px;
    margin-bottom: 16px;
    color: #bfbfbf;
  }

  .empty-text {
    font-size: 26px;
    font-weight: 500;
    color: #595959;
    margin-bottom: 8px;
  }

  .empty-tip {
    font-size: 22px;
    color: #8c8c8c;
  }
}

@media (max-width: 600px) {
  .search-item {
    flex-direction: column;

    .item-img {
      width: 100%;
      height: 160px;
    }
  }

  .search-container {
    padding: 15px;
  }
}
</style>
